<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/stylesite.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/styleleft.css" medial="all" />
<link rel="stylesheet" type="text/css" href="../css/mystyle.css" />
<script type="text/javascript" src="../js/jquery-1.8.2.min.js"></script>
<style>
    a{color: blue;}
    a:hover{color: #f80c0c;}
</style>
	<script src="../js/jquery-1.8.2.min.js" ></script>
	<script src="../js/image.js" type="text/javascript"></script>
         <script src="../js/jsearch.js" type="text/javascript"></script>  
    <script type="text/javascript">
        var xmlHttp;
		function showProduct_cate(str)
		{
                     var xmlHttp;
                if (window.XMLHttpRequest)
                {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlHttp=new XMLHttpRequest();

                }
                else
                {
                    // code for IE6, IE5
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
		        xmlHttp.onreadystatechange=function()
                {
                    if (xmlHttp.readyState==4)
					{
                        if (xmlHttp.status == 200) 
						{
						// 	window.alert("test thoi");
				//            document.myform.anbum.value=xmlHttp.responseText;
                     		document.getElementById('content').innerHTML=xmlHttp.responseText;
                       }
                        else {
                            // Có lỗi! Thông báo ngay!
                            alert('Lỗi!!!');
                        }
                    }
                    else {
                         document.getElementById("content").innerHTML='<img src="../Data/ajax-loader.gif"/>';
                    }
                }
                var url='v_showProduct.php';
				var test;
				//test=document.getElementById('idselect').value;
				//test=document.myform.select1.value;
				url=url+"?ID_category="+str;
				
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
		}
   
		
	</script>
   
<title>QUẢN LÝ DANH MỤC</title>
</head>

<body class="pagebody">
	<div id="wrapwebsite" >
             <?php 
            include('../element/header_adm.php');
                                ?>
            <div class="imagestop"></div>
            <div class="wrapmaincontent">
                <div id="maincontent">
                    <?php
                    if(!isset($_SESSION['user'])|| $_SESSION['user'][4]!='admin')
                        {      
                            echo '<p>Bạn không được quyền xem trang này</p>';
                             header ('location:/cfshop/home.php');
                        }
                        else
                        {
                    ?>
                    <?php
                        include 'product_model.php';
                        $display=5;
                            if(isset($_GET['page'])&&(int)$_GET['page'])
                            {
                                $page=$_GET['page'];	
                            }
                            else 
                            {
                                $page= getRecordProduct($display);
                            }
                            $start=(isset($_GET['start']) && (int)$_GET['start']>=0) ? $_GET['start'] :0;
		?>
                    <p>Chọn sản phẩm trong danh mục</p><select name="selectCate" id="select" onChange="showProduct_cate(this.value)" >
                        <?php
                            include_once '../adm_Category/category_model.php';
                            $arr_category=array();
                            $arr_category=  getAllCategory();
                            foreach ($arr_category as $category) {
                                echo '<option value="'.$category['ID'].'">'.$category['CategoryName'].'</option>';
                            }
                        ?>
                  	
                  </select>
                  <div class="idAdd">
                  <p >Add New Product</p>
                  <a href="v_addNewProduct.php"> <img src="../images/1318903087_add_small.ico" width="30px" height="30px" id="imgcate" onClick="addNewProduct()" /></a>
                 </div>
                     
                    <div id="content">
                  <?php
                      if(isset($_GET['ID_category']))
                      {
                        $Categoryid=$_GET['ID_category'];
                        $arr_pro=array();
                        
                        $arr_pro= getProduct($Categoryid);
                        $tendanhmuc=array();
                        $tendanhmuc= getCategoryName($Categoryid);
                        if($arr_pro!=NULL && $tendanhmuc!=NULL)
                        {
                        echo '<table width="900px" class="table">';
                        echo '<tr align="center">';
                        echo "<td colspan='8'><b>Danh sách sản phẩm --<font color='red'>".$tendanhmuc[6]."</font>-- </b></td>";
                        echo '</tr>';
                        echo '<tr align="center">';
                        echo '<td><b>ID</b></td>';
                        echo '<td><b>Tên sản phẩm</b></td>';
                        echo '<td><b>Mô tả</b></td>';
                        echo '<td><b>Giá</b></td>';
                        echo '<td><b>Size</b></td>';
                         echo '<td><b>Khuyến mãi</b></td>';
                        echo '<td><b>Image</b></td>';
                        echo '<td><b>Xoá</b></td>';
                         echo '<td><b>Sửa</b></td>';
                        echo '</tr>';
                        echo '<tr>';
                            foreach ($arr_pro as $product) {
                                echo "<td>".$product[0]."</td>";
                                echo "<td>".$product[1]."</td>";
                                echo "<td>".$product[2]."</td>";
                                echo "<td>".$product[3]."</td>";
                                echo "<td>".$product[4]."</td>";
                                echo "<td>".$product[7]."</td>";
                                echo '<td> <img  width="133px" height="160px" src="'.$product[5].'" /></td>';
                        echo '<td align="center"><a href="v_productEdit.php?IDProduct='.$product[0].'"><img src="../images/1352648277_message_edit.png" width="30px" height="30px" /></a></td>';
                        echo '<td align="center"><a href="c_addNewProduct.php?IDProduct='.$product[0].'"><img src="../images/1318498996_DeleteRed.ico" width="30px" height="30px"  /></a></td>';
                        echo '</tr>'; 
                         }
                        }
                         else
                             echo 'Chưa có sản phẩm nào, vui lòng thêm sản phẩm!!';
                      }
                        else
                        {
                            ?>
                        <div class="botcontentright">
                            <ul class="nav">
                                 <?php 
                        if($page>1)
                        {//hien thi so trang
                            $next=$start+$display;
                            $prev=$start-$display;
                            $current=($start/$display)+1;
                            //hien thi trang Previous
                            if($current!=1)
                            {
                                    echo "<li><a href='v_product_manage.php?start=$prev'>Previous</a></li>";
                            }
                            //Hien thi so link
                            for($i=1;$i<=$page;$i++)
                            {
                                    if($current!= $i){
                                            echo "<li><a href='v_product_manage.php?start=".($display*($i-1))."'>$i</a></li>";
                                            
                                            }
                                    else {
                                            echo '<li class="currentpage">'.$i.'</li>';	
                                    }

                            }
                            //hien thi trang Next
                            if($current!=$page)
                            {
                                    echo "<li><a href='v_product_manage.php?start=$next'>Next</a></li>";
                            }
                        }
			
                        ?>
                            </ul>
                         
                        </div>
                        
                        <?php
                        $arr_all=array();
                        $arr_all=  getProducts($start,$display);
                        if($arr_all!=NULL )
                        {
                        echo '<table width="900px" class="table">';
                        echo '<tr align="center">';
                        echo "<td colspan='9'><b>Danh sách sản phẩm </b></td>";
                        echo '</tr>';
                        echo '<tr>';
                        echo '<td><b>ID</b></td>';
                        echo '<td><b>Tên SP</b></td>';
                        echo '<td><b>Mô tả</b></td>';
                        echo '<td><b>Giá</b></td>';
                        echo '<td><b>Size</b></td>';
                        echo '<td><b>Khuyến mãi</b></td>';
                        echo '<td><b>Image</b></td>';
                         echo '<td><b>Thuộc danh mục</b></td>';
                        echo '<td><b>Sửa</b></td>';
                         echo '<td><b>Xoá</b></td>';
                        echo '</tr>';
                        echo '<tr>';
                            foreach ($arr_all as $product) {
                                echo "<td>".$product[0]."</td>";
                                echo "<td>".$product[1]."</td>";
                                echo "<td>".$product[2]."</td>";
                                echo "<td>".$product[3]."</td>";
                                echo "<td>".$product[4]."</td>";
                                echo "<td>".$product[7]."%</td>";
                                echo '<td> <img  width="133px" height="160px" src="'.$product[5].'" /></td>';
                                echo "<td>".$product[6]."</td>";
                        echo '<td align="center"><a href="v_productEdit.php?IDProduct='.$product[0].'"><img src="../images/1352648277_message_edit.png" width="30px" height="30px" /></a></td>';
                        echo '<td align="center"><a href="c_addNewProduct.php?IDProduct='.$product[0].'"><img src="../images/1318498996_DeleteRed.ico" width="30px" height="30px"  /></a></td>';
                        echo '</tr>'; 
                         }
                        }
                        else
                            echo 'Chưa có sản phẩm nào, Vui lòng nhập sản phẩm!!'; 
                        }
                      
                  ?>
                       
                        
                    </div>
                    
                </div>
           </div>
            <?php 
                        }
                  ?>
        </div>
    
</body>
</html>
